package middleware

import (
	"strings"

	"github.com/beego/beego/v2/server/web/context"
)

// BasicAuth 简单认证示例，要求请求需提供 "Authorization: Bearer <token>"
func BasicAuth(ctx *context.Context) {
	auth := ctx.Input.Header("Authorization")
	// 此处硬编码检查 token，可根据需求调整或从配置读取
	if auth == "" || !strings.EqualFold(auth, "Bearer my-secret-token") {
		ctx.Output.SetStatus(401)
		ctx.Output.Body([]byte("Unauthorized"))
	}
}
